package com.example.multi_db.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.multi_db.entity.Student;
import com.example.multi_db.entity.VideoOrder;
import com.example.multi_db.mapper.StudentMapper;
import com.example.multi_db.mapper.VideoOrderMapper;
import com.example.multi_db.service.SyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description
 * @Author lihw
 * @Date 2023/12/6 15:03
 */
@Service
public class SyncServiceImpl implements SyncService {

    @Autowired
    private VideoOrderMapper videoOrderMapper;

    @Autowired
    private StudentMapper studentMapper;

    @DS("source")
    @Override
    public List<Object> readList() {
        List<VideoOrder> videoOrders = videoOrderMapper.selectList(null);
        List<Object> collect = videoOrders.stream().map(item -> (Object) item).collect(Collectors.toList());
        return collect;
    }

    @DS("target")
    @Override
    public void writeList(List<Object> list) {

        List<Student> students = studentMapper.selectList(null);
        System.out.println(students);
    }
}
